﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using ETA.Entity;
using ETA.IRepository;
using ETA.IService;
using ETA.Dtos;

namespace ETA.Service
{
    public class JoinApplyFormService : IJoinApplyFormService
    {

        #region 属性

        private IJoinApplyFormRepository _IJoinApplyFormRepository { set; get; }

        #endregion

        #region 构造函数

        public JoinApplyFormService(IJoinApplyFormRepository IJoinApplyFormRepository)
        {
            _IJoinApplyFormRepository = IJoinApplyFormRepository;
        }

        #endregion

        #region IJoinApplyFormService 成员

        public QueryJoinApplyFormResponse QueryJoinApplyFormList(QueryJoinApplyFormRequest req, out int count)
        {
            count = 0;
            var response = new QueryJoinApplyFormResponse();
            try
            {
                var joinApplyForm = new JoinApplyForm();
                if (!string.IsNullOrEmpty(req.AddressCity))
                {
                    joinApplyForm.AddressCity= req.AddressCity;
                }
                if (!string.IsNullOrEmpty(req.AddressProvice))
                {
                    joinApplyForm.AddressProvice = req.AddressProvice;
                }
                if (!string.IsNullOrEmpty(req.AddressSuffix))
                {
                    joinApplyForm.AddressSuffix = req.AddressSuffix;
                }
                if (!string.IsNullOrEmpty(req.AddressZone))
                {
                    joinApplyForm.AddressZone = req.AddressZone;
                }

                if (!string.IsNullOrEmpty(req.CompanyName))
                {
                    joinApplyForm.CompanyName = req.CompanyName;
                }

                if (!string.IsNullOrEmpty(req.CompanyType))
                {
                    joinApplyForm.CompanyType = req.CompanyType;
                }

                if (req.JoinApplyType!=null)
                {
                    joinApplyForm.JoinApplyType = req.JoinApplyType;
                }

                if (req.HandlerStatus != null)
                {
                    joinApplyForm.HandlerStatus = req.HandlerStatus;
                }

                if (req.JoinFormId != null)
                {
                    joinApplyForm.JoinApplyFormId = req.JoinFormId;
                }

                var list = _IJoinApplyFormRepository.GetJoinApplyFormByFilter(joinApplyForm, req.Sdate, req.Edate, req.Page, req.PageSize, out count);
                response.JoinApplyForms = list;
                response.Result.IsSuccess = true;
            }
            catch (Exception e)
            {
                response.Result.ErrMessage = e.Message;
                response.Result.IsSuccess = false;
            }
            return response;
        }


        public List<JoinApplyFormDto> ConvertToJoinApplyFormDto(List<JoinApplyForm> list)
        {
            var res = new List<JoinApplyFormDto>();

            return res;
        }

        public CreateJoinApplyFormResponse CreateJoinApplyForm(CreateJoinApplyFormRequest req)
        {
            var res = new CreateJoinApplyFormResponse();
            try
            {
                if (req != null)
                {
                    req.JoinApplyForm.JoinApplyFormId = _IJoinApplyFormRepository.GenerateNo("", 5);
                    req.JoinApplyForm.CreateDate = DateTime.Now;
                    res.JoinApplyForm = _IJoinApplyFormRepository.Insert(req.JoinApplyForm);
                    res.Result.IsSuccess = true;
                }
            }
            catch (Exception e)
            {
                res.Result.IsSuccess = false;
                res.Result.ErrMessage = e.Message;
            }
            return res;
        }

        public ModifyJoinApplyFormResponse ModifyJoinApplyForm(ModifyJoinApplyFormRequest req)
        {
            var res = new ModifyJoinApplyFormResponse();
            try
            {
                if (req != null)
                {
                    res.JoinApplyForm = _IJoinApplyFormRepository.Update(req.JoinApplyForm);
                    res.Result.IsSuccess = true;
                }
            }
            catch (Exception e)
            {
                res.Result.IsSuccess = false;
                res.Result.ErrMessage = e.Message;
            }
            return res;
        }

        #endregion
    }
}
